{**************************************************************************************************}
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the    }
{ License at http://www.mozilla.org/MPL/                                                           }
{                                                                                                  }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF   }
{ ANY KIND, either express or implied. See the License for the specific language governing rights  }
{ and limitations under the License.                                                               }
{                                                                                                  }
{ The Original Code is ConsoleParameters.pas                                                       }
{                                                                                                  }
{ The Initial Developer of the Original Code is Fabrizio Vita (fabrizio.vita@itacasoft.com)        }
{**************************************************************************************************}
unit ConsoleParameters;

interface

uses Classes, Sysutils;

function IndexOfSwitch(sw: string): integer;
function SwitchExists(sw: string): boolean;

implementation

function SwitchExists(sw: string): boolean;
var
   i, ipos: integer;
   str: string;
begin
   for I := 1 to ParamCount do
   begin
      ipos := pos('-', ParamStr(i));
      if ipos > 0 then
      begin
         str := copy(paramstr(i), 2, length(paramstr(i)));
         str := trim(str);
         if str = sw then
         begin
            result := true;
            exit;
         end;
      end;
   end;

   result := false;
end;


function IndexOfSwitch(sw: string): integer;
var
   i, ipos: integer;
   str: string;
begin
   for I := 1 to ParamCount do
   begin
      ipos := pos('-', ParamStr(i));
      if ipos > 0 then
      begin
         str := copy(paramstr(i), 2, length(paramstr(i)));
         str := trim(str);
         if str = sw then
         begin
            result := i;
            exit;
         end;
      end;
   end;

   result := 0;
end;

end.
